package com.x.config;

import cn.hutool.crypto.symmetric.AES;
import com.x.utils.JasyptUtils;
import org.jasypt.encryption.StringEncryptor;
import org.springframework.beans.factory.annotation.Value;

import java.nio.charset.StandardCharsets;

/**
 * the class of advance
 *
 * 实现解密并把数据返显回配置文件
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2024-06-12
 */
public class MyEncryptor implements StringEncryptor {

    @Value("${jasypt.encryptor.password:}")
    private String decryptPassword;

    private MyEncryptablePropertyDetector propertyDetector;

    public MyEncryptor() {
    }

    public MyEncryptor( MyEncryptablePropertyDetector propertyDetector) {
        this.propertyDetector = propertyDetector;
    }

    /**
     *这里是加密方法，我们不在这里加密，原参数返回
     */
    @Override
    public String encrypt(String s) {
        return s;
    }

    @Override
    public String decrypt(String s) {
        return JasyptUtils.decrypt(s.substring(4, s.length() - 1), decryptPassword);
    }
}
